package bit_operation;

public class missingNumber {
    public int missingNumber(int[] nums) {
        int x = 0;
        for(int i = 0;i <nums.length;i++) {
            x = x ^ i;
            x = x^nums[i];
        }
        x = x^nums.length;
        return x;
    }
    public int missingNumber1(int[] nums) {
        int n = nums.length;
        int[] hash = new int[n+1];

        for(int x:nums) {
            hash[x]++;
        }
        for(int i = 0;i < n+1;i++) {
            if(hash[i] == 0) {
                return i;
            }
        }
        return -1;
    }
}
